import router from './router';
import { start, close } from '@/utils/nprogress.js';
import { getCookies } from '@/utils/cache.js';
const whiteList = ['/login', '/ForgetPassword', '/Home'];
router.beforeEach(async (to, from, next) => {
	start();
	const token = getCookies('TOKEN');
	if (whiteList.includes(to.path)) {
		// 判断白名单页面 直接跳转
		next();
	} else if (!token) {
		// 判断有没有登录
		next('/login');
	} else {
		next();
	}
});

router.afterEach(() => {
	close();
});

router.onError((err) => {
	close();
});
